package com.wqtz.chechai.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.wqtz.chechai.R;

import butterknife.internal.Utils;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2017/1/5 14:24
 */

public class WQTZProgressView extends View {
	private boolean isCurrentLevel = true; // 是否绘制的是当前等级视图

	private Paint dividerLinePaint; // 分割线渲染器

	private Paint bitmapPaint; // 图片渲染器

	private int dividerLineColor = getResources().getColor(R.color.gray_border); // 分割线颜色

	private boolean isNeedDividerLine = true;

	public void setCurrentLevel(boolean currentLevel) {
		isCurrentLevel = currentLevel;
	}

	public void setNeedDividerLine(boolean needDividerLine) {
		isNeedDividerLine = needDividerLine;
	}

	public WQTZProgressView(Context context) {
		super(context);
		init();
	}

	public WQTZProgressView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	/**
	 * 初始化
	 */

	private void init() {
		dividerLinePaint = new Paint();
		bitmapPaint = new Paint();
		bitmapPaint.setAntiAlias(true);
		dividerLinePaint.setColor(dividerLineColor);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);

		/**
		 * 绘制图标部分
		 */
		RectF rectF = new RectF(0, 0, 15, 15);
		Bitmap currentLevelBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_finger_unselected);
		Bitmap notCurrentLevelBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.icon_finger_unselected);
		if (isCurrentLevel) {
			canvas.drawBitmap(currentLevelBitmap, null, rectF, bitmapPaint);
		} else {
			canvas.drawBitmap(notCurrentLevelBitmap, null, rectF, bitmapPaint);
		}

		/**
		 * 绘制线条部分
		 */

		float startX = (float) 7.5;
		float startY =15;
		float endX = startX;
		float endY = getHeight();
		dividerLinePaint.setStrokeWidth(2);
		if (isNeedDividerLine) {
			canvas.drawLine(startX, startY, endX, endY, dividerLinePaint);
		}
	}

}
